#!/bin/bash

if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
	sudo apt-get update -qq
	if [[ $? != 0 ]]; then
		echo "cannot update"
		exit 1
	fi

	sudo apt-get install -qq \
	    cvs \
	    git \
	    mercurial \
	    cssc \
	    bzr \
	    subversion \
	    monotone \
	    rcs \
	    rcs-blame \
	    python3 \
	    python3-venv \
	    python3-pip \
	    nodejs \
	    jq
	if [[ $? != 0 ]]; then
		echo "cannot install extra packages"
		exit 1
	fi

	# Bitkeeper install failure is not critical, so exit code is not checked.
	sudo ./dev/install-bitkeeper.sh

	sudo ./dev/install-python-packages.sh
	if [[ $? != 0 ]]; then
		echo "cannot install Python packages"
		exit 1
	fi
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
#	brew update
        export HOMEBREW_NO_AUTO_UPDATE=1

	brew install cvs libgit2 jq
	if [[ $? != 0 ]]; then
		echo "cannot install extra packages"
		exit 1
	fi

	brew install python3
	brew upgrade python

	./dev/install-python-packages.sh
	if [[ $? != 0 ]]; then
		echo "cannot install Python packages"
		exit 1
	fi
fi

sudo ./dev/install-universal_ctags.sh
if [[ $? != 0 ]]; then
	echo "cannot install Universal ctags"
	exit 1
fi

# for API blueprint verification
npm install drafter
